/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 *
 */

import { expect, test } from '@jest/globals';

import { FileUtil } from '../../../src/utils/file-util';
import { OhosLogger } from '../../../src/utils/log/ohos-logger';

test('test checkPathLength', () => {
  jest.spyOn(OhosLogger.prototype, 'errorMessageExit').mockImplementation(
    (message: string, ...args: unknown[]) => {
      throw new Error(message + args);
    }
  );
  const path1 = 'fjwoiew';
  expect(() => FileUtil.checkPathLength(path1)).not.toThrow();
  const path2 =
    'D:\\DevEcoStudioProjects\\MyApplication276\\entry\\build\\default\\intermediates\\res\\default11111111111' +
    '111111111111111111111111111111111111111111111111111111111111111111\\default111111111111111111111111111111' +
    '11111111111111111111111111111111111111111111111_resConfig.json';
  expect(() => FileUtil.checkPathLength(path2)).toThrowError();
});

test('test isSubDir', () => {
  expect(FileUtil.isSubDir('D:/a/b', 'D:/a/b/c')).toBeTruthy();
  expect(FileUtil.isSubDir('D:/a/b/c', 'D:/a/b')).toBeFalsy();
  expect(FileUtil.isSubDir('/a/b', '/a/b/c')).toBeTruthy();
  expect(FileUtil.isSubDir('/a/b/c', '/a/b')).toBeFalsy();
});
